import 'package:m_todo/domain/entity/account_entity.dart';
import 'package:m_todo/domain/store/base_account_store.dart';

/// 账号服务
class AccountService {
  final BaseAccountStore accountStore;

  AccountService(this.accountStore);

  /// 是否登陆
  Future<bool> isLogin() async {
    return await getLoginAccount() != null;
  }

  /// 查看当前登陆的用户
  Future<AccountEntity?> getLoginAccount() {
    return accountStore.getLoginAccount();
  }

  /// 通过用户名查询用户信息
  Future<AccountEntity?> getAccountByName(String name) {
    return accountStore.queryAccountByName(name);
  }

  /// 保存登陆状态
  Future<void> saveLoginState(AccountEntity accountEntity) {
    return accountStore.saveLoginAccount(accountEntity);
  }

  /// 删除登出状态
  Future<void> clearLoginState() {
    return accountStore.clearLoginAccount();
  }
}
